<?php
require_once('../../../conf/config.php.inc');
require_once(SYBMAS_LIB_PATH.'/liblogin.php.inc');
require_once(SYBMAS_LAYOUT_PATH.'/layout.php.inc');
require_once(SYBMAS_LIB_PATH.'/libsybmas.php.inc');
require_once(SYBMAS_LAYOUT_PATH.'/menu.php.inc');

require_once('../lib/libtablas.php.inc');
verificar_inicio_sesion();
?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="<?php echo LAYOUT_URI?>/sybmasstyle.css">
<script src="<?php echo LAYOUT_URI?>/jquery-1.2.1.min.js" type="text/javascript"></script>
<script src="<?php echo LAYOUT_URI?>/menu-collapsed.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="<?php echo LAYOUT_URI?>/style.css" >
<title>.:: Sybmas - Listado de tablas</title>
<!--[if lt IE 8]>
   <style type="text/css">
   li a {display:inline-block;}
   li a {display:block;}
   </style>
   <![endif]-->
</head>
<body>
<script src="<?php echo JAVASCRIPT_URI?>/tooltip/wz_tooltip.js"
	type="text/javascript"></script>
<center>
<div id="container">
<div id="header">
<?php generar_header();?>
</div>
<div id="scene">
<div id="modulos">
<ul id="menu" style="width: 150px;">
<?php generar_menu();?>
</ul>
</div>

<div id="title">Listar tablas</div>
<div id="main">
<?php 
$pagina=0;
$registrosPorPagina=10;
$dbname=$_SESSION['sybmas.user.dbname'];

foreach($_POST as $key => $value){
	$$key=$value;
}
$query="SELECT o.id,o.uid,o.name,o.type,u.name AS owner FROM ".
	"$dbname..sysobjects o, ".
	"$dbname..sysusers u ".
	"WHERE type='U' ".
	"AND o.uid=u.uid ".
	"ORDER BY o.name";
//echo "$query<br>";

$offset=$registrosPorPagina*$pagina;

sybase_min_server_severity(11);
$sybuser_connection=start_default_sybuser_connection();

$result=sybase_query($query,$sybuser_connection);	
$registrosTotales=$result?sybase_num_rows($result):0;
$paginas=ceil($registrosTotales/$registrosPorPagina);
$paginaAnterior=$pagina-1;
$paginaSiguiente=$pagina+1;

?>
<form id="form_cambiarbd" method="post"
	action="<?php echo $_SERVER['PHP_SELF']?>">	
<table>
	<tr>
		<td rowspan="2">
			Base de datos<br><br>
			<?php form_cambiarbd('form_cambiarbd'); ?>
		</td>		
		<td>Registros totales: <?php echo $registrosTotales?></td>
		<td>Pagina <?php echo $pagina+1?> de <?php echo $paginas?></td>		
	</tr>
	<tr>
		<td>Registros por pagina: <?php form_registrosPorPagina('form_cambiarbd');?></td>
		<td>
			<input type="image" src="<?php echo IMG_URI?>/resultset_first.png" value="Ultimo" 
				<?php echo ($paginaAnterior<0)?' disabled="disabled" ':''?>
				onclick="document.getElementById('pagina').value=0">
			<input type="image" src="<?php echo IMG_URI?>/resultset_previous.png" value="Anterior" 
				<?php echo ($paginaAnterior<0)?' disabled="disabled" ':''?>
				onclick="document.getElementById('pagina').value--">			
			<input type="image" src="<?php echo IMG_URI?>/resultset_next.png" value="Siguiente" 
				<?php echo ($paginaSiguiente>=$paginas)?' disabled="disabled" ':''?>
				onclick="document.getElementById('pagina').value++">		
			<input type="image" src="<?php echo IMG_URI?>/resultset_last.png" value="Ultimo" 
				<?php echo ($paginaSiguiente>=$paginas)?' disabled="disabled" ':''?>
				onclick="document.getElementById('pagina').value=<?php echo $paginas-1?>">
		
				
			<input type="hidden" name="pagina" id="pagina" value="<?php echo $pagina?>">
			
		</td>
	</tr>
</table>
</form>

<hr>


<table width="80%" border="1">
	<tr>
		<th>id</th>
		<th>prop.</th>
		<th>nombre</th>
		<th>tipo</th>
		<th></th>
	</tr>
	
<?php
if($result && $offset<$registrosTotales){
$i=0;
sybase_data_seek($result,$offset);
while($data=sybase_fetch_array($result)){
	if($i>=$registrosPorPagina){
		break;
	}
?>
	<tr>
		<td><?php echo $data['id']?></td>
		<td><?php echo $data['owner']?></td>
		<td><?php echo $data['name']?></td>
		<td><?php echo $data['type']?></td>
		<td width="80px"><a
			href="consultar/tabla.php?id=
		<?php 
			echo $data['id'];
			if($dbname){
				echo "&dbname=$dbname";	
			}
		?>" onmouseover="Tip('Detalle de la tabla ')" onmouseout="UnTip()"> 
			<img src="<?php echo IMG_URI?>/document_pen.png"
			alt="Detalles" width="19" height="19" border="0"> </a>

		<a
			href="borrar/tabla.php?id=
		<?php 
			echo $data['id'];
			if($dbname){
				echo "&dbname=$dbname";	
			}
		?>"onmouseover="Tip('Eliminar tabla')" onmouseout="UnTip()"> 
			<img src="<?php echo IMG_URI?>/document_delete.png"
			alt="Borrar" width="19" height="19	" border="0">
		</a>
		&nbsp;
		<a
			href="consultar/datostabla.php?id=
		<?php 
			echo $data['id'];
			echo "&tablename=".$data['name'];
			echo "&tableowner=".$data['owner'];
			if($dbname){
				echo "&dbname=$dbname";	
			}
		?>"onmouseover="Tip('Explorar datos')" onmouseout="UnTip()"> 
			<img src="<?php echo IMG_URI?>/table.png"
			alt="Explorar" width="19" height="19	" border="0">
		</a>
		
		</td>
	</tr>
<?php
	$i++;
}//$data=sybase_fetch_array($result)

sybase_free_result($result);
}//
?>
</table>
	
<?php
//Cerrando conexiones a la base de datos
sybase_close($sybuser_connection);
?>
</div>
</div>
<?php generar_footer();?></div>
</center>
</body>
</html>
